<template>
  <div class="exchange">
    <div class="exchange-top">
      <van-icon name="arrow-left" class="btn-back" @click="goBack" />
    </div>
    <div class="top">
      <div class="top-l">
        <span class="icon-gift"></span>
        <span class="mon">{{dataa.money}}</span>
        {{unitName}}
      </div>
      <div class="top-r">
        <span class="icon-gift"></span> 兑换记录
      </div>
    </div>
    <div class="list">
      <div class="item" v-for="(items,index) in datalist" :key="items.id">
        <div class="item-top">
          <img v-lazy="items.image" alt />
        </div>

        <div class="item-bot">
          <div class="fir">
            <span
              class="isvip"
              :style="`background:${price2[index]}`"
              v-show="price1[index]"
            >{{price1[index]}}</span>
            <span class="discri">{{items.title}}</span>
          </div>
          <div class="sec">{{items.titleDownTxt}}</div>
          <div class="thr">
            <span>兑换</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data: () => ({
    datalist: [],
    unitName: "",
    datainfo: {},
    price1: [],
    price2: [],
    dataa: {
      money: 999
    }
  }),
  created() {
    this.getlist();
    this.getinfo();
    this.getstorage();
  },
  methods: {
    async getlist() {
      const {
        data: {
          data: { list, unitName },
          success
        }
      } = await this.$axios.get("/api/getmime1");
      console.log(list);
      if (success !== true) return this.$Toast("获取失败");
      this.datalist = list;
      this.unitName = unitName;
      this.datalist.forEach(item => {
        this.price1.push(item.tagText.split(",")[0]);
        this.price1.push(item.tagText.split(",")[1]);
      });
    },
    async getinfo() {
      const {
        data: { data, success }
      } = await this.$axios.get("/api/getmime2");
      if (success !== true) return this.$Toast("获取失败");
      this.datainfo = data;
    },
    goBack() {
      this.$router.go(-1);
    },
    getstorage() {
      if (localStorage.getItem("user")) {
        this.dataa = JSON.parse(localStorage.getItem("user"));
      }
    }
  }
};
</script>
<style lang="less" scoped>
.exchange {
  background: #f8fafc;
  .top {
    background: #fff;
    font-size: 12px;
    color: #333;
    padding: 10px;
    display: flex;
    .icon-gift {
      width: 20px;
      height: 20px;
      display: inline-block;
      background-image: url(//yun.duiba.com.cn/images/201910/5ct8k57k7w.jpg);
      background-size: 100%;
      vertical-align: -6px;
    }
    .top-l {
      display: inline-block;
      padding: 10px;
      border-right: 1px solid #ddd;
      flex: 1;

      .mon {
        color: #fd5746;
        margin: 0 7px;
      }
    }
    .top-r {
      padding: 10px;
      display: inline-block;
      flex: 1;
    }
  }
  .list {
    display: flex;
    flex-wrap: wrap;
    .item {
      display: flex;
      width: 50%;
      box-sizing: border-box;
      border-right: 1px solid #eee;
      border-bottom: 1px solid #eee;
      flex-direction: column;
      img {
        width: 100%;
        height: 100%;
        border: 0;
      }
      .item-bot {
        background: #fff;
        padding: 0 15px;
        .fir {
          margin-top: 14px;
          display: flex;
        }
        .isvip {
          background: #f0d98d;
          border-radius: 8px;
          font-size: 12px;
          color: #fff;
          padding: 0 5px;
          display: inline-block;
        }
        .discri {
          font-size: 14px;
          color: #333;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          display: inline-block;
          width: 76px;
          margin-left: 3px;
          vertical-align: -5px;
          flex: 1;
        }
        .sec {
          color: #fd5746;
          font-size: 12px;
          margin-top: 5px;
        }
        .thr {
          width: 100%;
          text-align: right;
          span {
            display: inline-block;
            border: 1px solid #fd5746;
            font-size: 12px;
            border-radius: 12px;
            padding: 2px 14px;
            margin-bottom: 10px;
            color: #fd5746;
          }
        }
      }
    }
  }
}
.exchange-top {
  position: fixed;
  top: 11px;
  left: 0;
  .btn-back {
    width: 3.2vw;
    height: 3.2vw;
    color: #fd5746;
    size: 16px;
    margin-top: 10px;
  }
}
</style>
